package com.qianfeng.openapi.web.master;


//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                            O\ = /O
//                        ____/`---'\____
//                      .   ' \\| |// `.
//                       / \\||| : |||// \
//                     / _||||| -:- |||||- \
//                       | | \\\ - /// | |
//                     | \_| ''\---/'' | |
//                      \ .-\__ `-` ___/-. /
//                   ___`. .' /--.--\ `. . __
//                ."" '< `.___\_<|>_/___.' >'"".
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                 \ \ `-. \_ __\ /__ _/ .-` / /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//
//         .............................................
//                  佛祖镇楼                  BUG辟易
//          佛曰:
//                  写字楼里写字间，写字间里程序员；
//                  程序人员写程序，又拿程序换酒钱。
//                  酒醒只在网上坐，酒醉还来网下眠；
//                  酒醉酒醒日复日，网上网下年复年。
//                  但愿老死电脑间，不愿鞠躬老板前；
//                  奔驰宝马贵者趣，公交自行程序员。
//                  别人笑我忒疯癫，我笑自己命太贱；


import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.web.master.feign.CacheService;
import com.qianfeng.openapi.web.master.mq.SendApiRoutingChangeStream;
import com.qianfeng.openapi.web.master.pojo.ApiMapping;
import com.qianfeng.openapi.web.master.service.ApiMappingService;
import com.qianfeng.plateform2203.common.constants.RedisConstants;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.List;

@SpringBootApplication
@MapperScan("com.qianfeng.openapi.web.master.mapper")
@EnableFeignClients
@EnableBinding({SendApiRoutingChangeStream.class})
public class WebMasterStartApp {
    public static void main (String[] args){
        final ConfigurableApplicationContext context = SpringApplication.run(WebMasterStartApp.class, args);

        // 缓存预热
        final ApiMappingService apiService = context.getBean(ApiMappingService.class);

        final PageInfo<ApiMapping> mappingList = apiService.getMappingList(null, 1, 100);
        final List<ApiMapping> list = mappingList.getList();

        final CacheService cacheService = context.getBean(CacheService.class);
        for (ApiMapping apiMapping : list) {
            cacheService.hmset(RedisConstants.APIRouting_REDIS_PRE+apiMapping.getGatewayApiName(),
                    apiMapping);
        }

    }
}
